<template>
  <div>
    <Button type="success" :to="{path:'product-add',query:{}}">
      添加产品
    </Button>

    <Table stripe :columns="columns" :data="data"></Table>

    <row style="margin-top: 10px">
      <i-col align="right">
        <Page show-sizer :total="total" show-total @on-change="onChange" @on-page-size-change="onPageSizeChange"/>
      </i-col>
    </row>

  </div>
</template>

<script>
  import {ProductFindAll,ProductDelete} from "../../../api/data"

  export default {
    data() {
      return {
        page: 1,//page 第几页
        pageSize: 10,//pageSize:每页几条数据
        total: 0,
        columns: [
          {
            title: '产品代码',
            key: 'code'
          },
          {
            title: '描述',
            key: 'description'
          },
          {
            title: '路线',
            key: 'routing'
          },
          {
            title: '操作',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                  //    console.log(params);
                      this.$router.push({
                        path: '/base-setting/product-update', query: {
                          code: params.row.code
                        }
                      })
                    }
                  }
                }, '编辑'),
                h('Button', {
                  props: {
                    type: 'error',
                    size: 'small'
                  },
                  on: {
                    click: () => {
                      this.$Modal.confirm({
                        title:'确认删除',
                        content:'是否要删除产品？',
                        onOk:()=>{
                          this.ProductDelete(params.row.code);
                        },
                        onCancel:()=>{}
                      })
                    },
                  }
                }, '删除')

              ]);
            }
          }

        ],
        data: [

        ]
      }
    },
    mounted() {
      this.ProductFindAll()
    },
    methods: {
      ProductFindAll() {
        var data = {
          page: this.page,
          pageSize: this.pageSize,
        };
        ProductFindAll(data).then(data => {
          if (data.data.code == 0) {
            this.data = data.data.data.list;
            this.total = data.data.data.total;
          }
        })
      },

      onPageSizeChange(pageSize) {
        this.page = 1;
        this.pageSize = pageSize;
        this.ProductFindAll();
      },
      onChange(page) {
        this.page = page;
        this.ProductFindAll();
      },
      ProductDelete(code){
        let data = {
          code:code
        }
        ProductDelete(data).then(res => {
          this.ProductFindAll();
        })
      },
    }
  }
</script>

<style lang="less">

</style>

